package com.shine.app.ui;

import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.shine.app.R;
import com.shine.app.commons.Commons;

public class PlayerActivity extends CalendarActivity {

	protected LinearLayout layout_player;
	protected LinearLayout search_player;
	protected ImageView search_player_imageView;
	protected TextView playerTextView;
	protected RelativeLayout player_one_imageView;
	protected RelativeLayout player_two_imageView;
	protected RelativeLayout player_three_imageView;
	protected RelativeLayout player_four_imageView;
	protected int player = Commons.PLAYER_TWO;

	protected void initPlayerView() {
		search_player = (LinearLayout) this.findViewById(R.id.search_player);
		layout_player = (LinearLayout) this.findViewById(R.id.layout_player);
		search_player_imageView = (ImageView) this
				.findViewById(R.id.search_player_image);
		search_player_imageView.setTag(false);
		playerTextView = (TextView) this.findViewById(R.id.text_player);
		player_one_imageView = (RelativeLayout) findViewById(R.id.one);
		player_two_imageView = (RelativeLayout) findViewById(R.id.two);
		player_three_imageView = (RelativeLayout) findViewById(R.id.three);
		player_four_imageView = (RelativeLayout) findViewById(R.id.four);

		setPlayer(player);
		player_one_imageView.setOnClickListener(new SelectPlayer(
				Commons.PLAYER_ONE));
		player_two_imageView.setOnClickListener(new SelectPlayer(
				Commons.PLAYER_TWO));
		player_three_imageView.setOnClickListener(new SelectPlayer(
				Commons.PLAYER_THREE));
		player_four_imageView.setOnClickListener(new SelectPlayer(
				Commons.PLAYER_FOUR));
	}

	public class SelectPlayer implements OnClickListener {
		private int player;

		public SelectPlayer() {
		}

		public SelectPlayer(int number) {
			this.player = number;
		}

		@Override
		public void onClick(View v) {
			switch (player) {
			case Commons.PLAYER_ONE:
				setPlayer(Commons.PLAYER_ONE);
				break;
			case Commons.PLAYER_TWO:
				setPlayer(Commons.PLAYER_TWO);
				break;
			case Commons.PLAYER_THREE:
				setPlayer(Commons.PLAYER_THREE);
				break;
			case Commons.PLAYER_FOUR:
				setPlayer(Commons.PLAYER_FOUR);
				break;
			default:
				break;
			}
		}
	}

	protected void resetBackground() {
		player_one_imageView
				.setBackgroundResource(R.drawable.searchlocation_player_noselect);
		player_two_imageView
				.setBackgroundResource(R.drawable.searchlocation_player_noselect);
		player_three_imageView
				.setBackgroundResource(R.drawable.searchlocation_player_noselect);
		player_four_imageView
				.setBackgroundResource(R.drawable.searchlocation_player_noselect);
	}

	protected void setPlayer(int number) {
		resetBackground();
		player = number;
		playerTextView.setText(String.valueOf(number));
		layout_player.setVisibility(View.GONE);
		search_player_imageView.setTag(false);
		search_player_imageView
				.setImageResource(R.drawable.searchlocation_below);
		if (Commons.PLAYER_ONE == number) {
			player_one_imageView
					.setBackgroundResource(R.drawable.searchlocation_player_select);
		} else if (Commons.PLAYER_TWO == number) {
			player_two_imageView
					.setBackgroundResource(R.drawable.searchlocation_player_select);
		} else if (Commons.PLAYER_THREE == number) {
			player_three_imageView
					.setBackgroundResource(R.drawable.searchlocation_player_select);
		} else if (Commons.PLAYER_FOUR == number) {
			player_four_imageView
					.setBackgroundResource(R.drawable.searchlocation_player_select);
		} else
			;
	}
}
